package org.example.service.impl;

import org.example.domain.Product;
import org.example.mapper.ProductMapper;
import org.example.qo.PageResult;
import org.example.qo.QueryObject;
import org.example.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 李新雨的项目86176
 * @version 1.0
 * @date 2024-12-03 9:07
 */
@Service
public class ProductServiceImpl implements IProductService {
    @Autowired
    private ProductMapper productMapper;

    @Override
    public void deleteByPrimaryKey(Long id) {
         productMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void insert(Product record) {
        productMapper.insert(record);
    }

    @Override
    public Product selectByPrimaryKey(Long id) {
        return productMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Product> selectAll() {
        return productMapper.selectAll();
    }

    @Override
    public void updateByPrimaryKey(Product record) {
        productMapper.updateByPrimaryKey(record);
    }

    @Override
    public PageResult<Product> selectPage(QueryObject queryObject) {
      int count= productMapper.selectFroCount(queryObject);
      if(count==0){

          return new PageResult<>(queryObject.getCurrentPage(),queryObject.getPageSize(),0,null);
      }
      List<Product> list=productMapper.selectForList(queryObject);

      return new PageResult<>(queryObject.getCurrentPage(),queryObject.getPageSize(),count,list);
    }
}
